package udpserver

import (
	"fmt"
	"runtime"
	"github.com/garyburd/redigo/redis"

)

var conn1 redis.Conn

//初始化redis连接
func init(){
	var err2 error
	conn1, err2 = redis.Dial("tcp", "192.168.1.109:6379")
	if err2 != nil {
		fmt.Println(err2)
		//log.Debug(err2)
	}
}

func Handlelabelinfo(info string)  {
	//fmt.Println("处理GPS标签数据")

	//fmt.Println("处理安全帽数据")
	//加到redis任务队列
	_,err1 := conn1.Do("PUBLISH", "channel3", info)
	if err1 != nil {
		fmt.Println("pub err: ", err1)
		return
	}



	        //新建任务并放入任务队列
			// 新建一个任务
			payLoad := Payload{Num: 1, Info:info}
			work := Job{Payload: payLoad}
			// 任务放入任务队列channal
			//fmt.Println("新任务入队列！")
			JobQueue <- work
			//fmt.Println("队列总长度:",cap(JobQueue))
			//fmt.Println("队列未消费任务数量:",len(JobQueue))
			//fmt.Println("JobQueue <- work")
			fmt.Println("当前协程数:", runtime.NumGoroutine())
			//time.Sleep(1 * time.Second)
}